pp108 : String Functions of Rule Engine

String Functions of Rule Engine

This topic describes the various string functions available in the rule engine function library.


String functions can be used to manipulate string values. You can convert strings to integers, return length of the strings, extract substrings, and remove leading and trailing spaces.

The following table describes the various string functions available in the rule engine function library and their usage.

Table 1. Rule Engine String Functions

String Functions

Description

Usage

number(e)

Converts a string expression into an integer.

number(e), where
e is a string expression that you want to convert into an integer.

string (e)

Converts a numeric expression into a string.

string(e), where
e is a numeric expression that you want to convert into a string.

string-length (e1)

Returns the number of characters in a given string.

string-length (e1), where
e1 is the string expression or string literal to calculate the length of the parameter.

normalize-space(' e1 ')

Removes the trailing spaces from the input string expression.

normalize-space(' e1 '), where
e1 is the string expression or string literal from which you want to remove the trailing spaces.For example:normalize-space(' Arnold ')The result of the above function is 'Arnold'.

concat(e1,e2)

Concatenates the given string parameters.

concat(e1,e2), where e1 and e2 are string expressions which you want to join.

starts-with(e1, e2)

Returns true if the first argument string starts with the second argument string, and otherwise returns false

starts-with(e1, e2), where e1 and e2 are strings, and returns true if the string e1 starts with the string e2.For example: starts-with('Arnold', 'A')The result of the above function istrue.

contains(e1, e2)

Returns true if the first argument string contains the second argument string, and otherwise returns false

contains(e1, e2), where e1 and e2 are strings, and returns true if the string e1 contains the string e2.For example: contains('Arnold', 'n')The result of the above function istrue.

substring-before(e1, e2)

Returns the start of string1 before string2 occurs in it

substring-before(e1, e2), where e1 and e2 are strings.For example: substring-before('Arnold', 'o')The result of the above function is 'Arn'

substring-after(e1, e2)

Returns the remainder of string1 after string2 occurs in it

substring-after(e1, e2), where e1 and e2 are strings.For example: substring-after('Arnold', 'n')The result of the above function is 'old'

substring(e1,x,y)

Returns the substring from the start position to the specified length. Index of the first character is

1. If length is omitted it returns the substring from the start position to the end

substring(e1,x,y), where e1 is the string, x is an integer which indicates the start position, y is an integer which indicates the length.For example: substring('Arnold', 2,3)The result of the above function is 'rno'

pos(e1,e2)

Returns the starting position (first index) of a specified string within the source string.

pos(e1,e2), where:

  • e1is the source string expression or string literal on which theposfunction will perform the search.
  • e2is a part of the string, or the target string expression, or the string literal to be searched in the source string (e1).
    For Example:pos('hello','e')- returns the value2.
    Note: If the
    pos function does not find a match of e2 in e1, it returns an integer value of 0.

rpos(e1,e2)

Calculates the starting position of a specified string from its rightmost occurrence within the source string.

rpos(e1,e2), where:

  • e1is the source string expression or string literal on which theposfunction will perform the search.
  • e2is a part of the string, or the target string expression, or the string literal to be searched in the source string (e1).
    For Example:rpos('racecar', 'c')- returns the value5.
    Note: If the
    rpos function does not find a match of e2 in e1, it returns an integer value of 0.

asc(e1)

Returns the ASCII code for a specified character.

asc(e1), where
e1 is the string representation of the character for which you want the ASCII code.For Example:asc('A')- returns the value 65.

chr(e1)

Returns the character represented by the given integer value.

chr(e1), where
e1 is a numeric expression representing the ASCII value of a character.For Example:chr(65)- returns the value A.